package com.kemai.designmode.ui
import android.os.Bundle
import com.kemai.common.adapter.ItemClickListener
import com.kemai.common.ui.BaseActivity
import com.kemai.designmode.R
import com.kemai.designmode.adapter.AppleAdapter
import com.kemai.designmode.adapter.BananaAdapter
import com.kemai.designmode.adapter.OrangeAdapter
import com.kemai.designmode.entry.Bag
import com.kemai.designmode.entry.bag.AppleBag
import com.kemai.designmode.entry.bag.BananaBag
import com.kemai.designmode.entry.bag.OrangeBag

//适配器模式调用(将对象有的东西但是不能本对象不能用的，借助其他对象进行适配)
class AdapterActivity : BaseActivity(), ItemClickListener {
    private val studyContent = arrayOf("苹果包装盒","香蕉包装盒","桔子包装盒")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_common_content)
        findViewById()
        setTiTle("适配器模式")
        setAdapterContent(studyContent,AdapterActivity@this,AdapterActivity@this)
    }

    override fun itemClick(position: Int) {
        var bag: Bag? = null
        when(position){
            0->{
                bag = AppleAdapter(BananaBag())
            }
            1->{
                bag = BananaAdapter(OrangeBag())
            }
            2->{
                bag = OrangeAdapter(AppleBag())
            }
        }
        bag?.pack()
    }

}